#include<iostream>
using namespace std;
template <class T> void SelectSort(T r[],int n);
template <class T>int length(T &arr);
template <class T>void print(T &arr);
int main()
{
    int a[]={6,4,2,7,61,4,2,72,4,2,7,6,4,2,75,2,7,61,4,2,72,4,2,7,6,4};
    SelectSort(a,length(a));
    print(a);
}
//选择排序法
template <class T> void SelectSort(T r[],int n)
{
    T change;
    for (int i = 0; i < n; i++)
    {
        int index=i;
        for (int j = i+1; j <= n; j++)
        {
            if (r[j]<r[index])
            {
                index=j;
            }
        }
        if(index!=i)
            {
                change=r[i];
                r[i]=r[index];
                r[index]=change;
            }
    }
}
//计算数组长度
template <class T>int length(T &arr)
{
    return sizeof(arr)/sizeof(arr[0]);
}
//打印数组元素
template <class T>void print(T &arr)
{
    for (int i = 0; i < length(arr); i++)
    {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}